package com.flesler.componentas.core.base
{
	import com.flesler.componentas.core.Component;
	import com.flesler.componentas.core.Entity;

	public class BaseComponent implements Component
	{
		private var _entity:Entity;
		private var _isDestroyed:Boolean = false;
		
		public function BaseComponent()
		{
		}
		
		// Component Implementation
		
		public function get entity():Entity
		{
			return _entity;
		}
		
		public function registerTo(entity:Entity):void
		{
			if (this.entity)
				throw new Error('This component was already registered to another entity');
			
			_entity = entity;
		}
		
		public function unregister():void
		{
			_entity = null;
		}
		
		// Initializable Implementation
		
		public function initialize():void
		{
		}
		
		// Destroyable Implementation

		public function get isDestroyed():Boolean
		{
			return _isDestroyed;
		}
		
		public function destroy():void
		{
			if (entity)
				unregister();
			_isDestroyed = true;
		}
	}
}
